
object IPV4HeaderChecker {
  def checksum(header: String): String = {
    val array = header.split(" ")
    val _hexStr = Integer.toHexString(array.map { x => Integer.parseInt(x,16) }.reduce((x, y) => x + y))
    val hexStr = _hexStr.length() match {
      case 5 => Integer.toHexString(Integer.parseInt(_hexStr.substring(1) ,16) + Integer.parseInt(_hexStr.substring(0, 1) ,16))
      case _ => _hexStr
    }
  
    array(5) = Integer.toHexString(Integer.parseInt("ffff" ,16) - Integer.parseInt(hexStr ,16))
    array.mkString(" ")
  }
}
